﻿using AnesSystem.Models;
using AnesSystem.Util;
using AnesSystem.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using System.Collections.ObjectModel;
using Microsoft.Win32;

namespace AnesSystem.Controls
{
    /// <summary>
    /// HistoryCtrl.xaml 的交互逻辑
    /// </summary>
    public partial class HistoryCtrl : UserControl
    {
        #region Variables

        #endregion

        #region Constructor
        public HistoryCtrl()
        {
            InitializeComponent();
            this.DataContext = HistoryCtrlViewModel.Instance;
            this._xuanZeDataGrid.LoadingRow += XuanZeDataGrid_LoadingRow;

            this.Loaded += HistoryCtrl_Loaded;
        }

        #endregion

        #region Properties

        #endregion

        #region 依赖属性

        #endregion

        #region Event

        #endregion

        #region Private Methods

        #endregion

        #region Public/Protected Methods

        #endregion

        #region EventHandlers
        private void XuanZeDataGrid_LoadingRow(object sender, DataGridRowEventArgs e)
        {
            e.Row.Header = e.Row.GetIndex() + 1;
        }

        private void HistoryCtrl_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                string command = (sender as Button).Tag.ToString();
                MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Visible;
                Task.Factory.StartNew(delegate
                {
                    Dispatcher.Invoke(delegate
                    {
                        HistoryCtrlViewModel.Instance.Excute(command);
                        MainPageCommonViewModel.Instance.WaitCtrlVisibility = Visibility.Collapsed;
                    });
                    
                });
            }
            catch (Exception ex)
            {
                Common.LogHelper.Error(GetType(), ex);
            }
        }

        private void _xuanZeDataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            SelPatientLinkModel model = _xuanZeDataGrid.SelectedValue as SelPatientLinkModel;
            if (model == null)
            {
                MessageBoxCommon.ShowDialog("请选择一个病人!", MessageBoxCommon.OK);
                return;
            }
            DataManager.Instance.CurrentPatientLink = model.PatientLink;
            MainPageCommonViewModel.Instance.NavigateTo("AnesRecordCtrl", false);
        }

        private void _roomsCmbCtrl_SelectedChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        #endregion

    }
}
